<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>文件上传</title>
	<link rel="stylesheet" href="/bootstrap/css/bootstrap.css">
	<style>
		form {
			margin-top: 30px;
		}
	</style>
</head>
<body>
<div class="container">

	<div class="row">
		<div class="col-md-4 col-sm-4"></div>
		<div class="col-md-4 col-sm-4">
			<h2> FastDFS 文件上传</h2>
			<form id="inputForm" th:action="@{/fdfs/upload}" method="post" enctype="multipart/form-data">
				<div class="form-group">
					<input type="file" name="file" id="file"  onchange="javascript:changeFile(this);">
				</div>
				<label>
					<input  onclick="submitClick();"   class="btn btn-default" value="上传" />
				</label>
			</form>
		</div>
		<div class="col-md-4 col-sm-4"></div>
	</div>
</div>
</body>
<script type="text/javascript">

	function changeFile(obj){
		let fileSize = obj.files[0].size;
		if(fileSize>10*1024*1024){
			alert("文件不能大于10Mb！");
			obj.outerHTML=obj.outerHTML;
		}
	}

	function submitClick() {

		let size = document.getElementById("file").files[0];
		if(size){
			document.getElementById("inputForm").submit();
		}else {
			alert("请选择文件");
		}

	}


</script>
</html>
